package com.yanmushi.ms.zuul;

import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author yinlei
 * @Date 2018/4/26
 * @Desc todo
 */
@Component
public class CustomFilter extends ZuulFilter {
    private static final Logger log = LoggerFactory.getLogger(CustomFilter.class);
    @Override
    public String filterType() {
        return "pre";
    }

    @Override
    public int filterOrder() {
        return 0;
    }

    @Override
    public boolean shouldFilter() {
        return true;
    }

    @Override
    public Object run() {
        RequestContext requestContext = RequestContext.getCurrentContext();
        HttpServletRequest request = requestContext.getRequest();
        String url = request.getRequestURI();
        String method = request.getMethod();

        log.info("url: {}, method: {}", url, method);

        return null;
    }
}
